import request from '../utils/request'

export interface User {
  id?: number
  username: string
  email: string
  password?: string
  user_type: 'student' | 'teacher' | 'staff' | 'admin'
  department: string
  status: 'active' | 'disabled'
}

export interface LoginForm {
  username: string
  password: string
}

export const userApi = {
  login(data: LoginForm) {
    return request.post('/api/users/login', data)
  },

  list(page: number, pageSize: number) {
    return request.get('/api/users', { 
      params: { 
        page, 
        page_size: pageSize 
      } 
    })
  },

  getById(id: number) {
    return request.get(`/api/users/${id}`)
  },

  create(user: Omit<User, 'id' | 'status'>) {
    return request.post('/api/users', user)
  },

  update(id: number, user: Partial<User>) {
    return request.put(`/api/users/${id}`, user)
  },

  delete(id: number) {
    return request.delete(`/api/users/${id}`)
  },

  updateStatus(id: number, status: User['status']) {
    return request.put(`/api/users/${id}/status`, { status })
  }
}
